﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebBanHang.GUI
{
    public partial class DNLogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.UrlReferrer != null)
                    ViewState["RefUrl"] = Request.UrlReferrer.ToString();

                if (CurrentContext.IsLogged)
                {
                    Response.Redirect("~/GUI/DoanhNghiep/DNDangNhap.aspx");
                }
            }
        }

        protected void btnDangNhap_Click(object sender, EventArgs e)
        {
            DNGH dn = new DNGH(txtTenDangNhap.Text, txtMatKhau.Text);
            if (dn.IsValidLogin())
            {
                Response.Cookies["UserDangNhap"].Value = dn.TenDangNhap;
                if (CheckBox1.Checked)
                {
                    Response.Cookies["UserDangNhap"].Expires = DateTime.Now.AddDays(7);
                }
                CurrentContext.don   = dn ;
                string url = ViewState["RefUrl"] == null ? "~/GUI/DNDangNhap.aspx" : ViewState["RefUrl"].ToString();
                Response.Redirect(url);
            }
        }
    }
}